import Vue from 'vue'
import App from './App.vue'
import router from './router'
import axios from 'axios'
import './plugins/element.js'
import './assets/css/global.css'
// 导入字体图标
import './assets/fonts/iconfont.css'
// 导入表格树
import TreeTable from 'vue-table-with-tree-grid'
// 导入富文本编辑器
import VueQuillEditor from 'vue-quill-editor'
// 导入富文本编辑器样式
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
// 导入NProgress, 包对应的JS和CSS
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

const BASEURL = 'https://www.liulongbin.top:8888/api/private/v1/'
axios.defaults.baseURL = BASEURL
axios.interceptors.request.use((config) => {
  NProgress.start();
  config.headers.Authorization = window.sessionStorage.getItem('token')
  return config
}, error => {
  return Promise.reject(error)
})
axios.interceptors.response.use((res) => {
  NProgress.done();
  return res.data
}, (error) => {
  return Promise.reject(error)
})
Vue.prototype.$http = axios
Vue.prototype.BASEURL = BASEURL

// 组件全局注册 表格树
Vue.component('tree-table', TreeTable)
// 全局注册富文本编辑器
Vue.use(VueQuillEditor)
Vue.filter('dataFormat', originVal => {
  const dt = new Date(originVal);

  const y = dt.getFullYear();
  const m = dt.getMonth() + 1;
  const d = (dt.getDate() + '').padStart(2, '0');
  const hh = (dt.getHours() + '').padStart(2, '0');
  const min = (dt.getMinutes() + '').padStart(2, '0')
  const sin = (dt.getSeconds() + '').padStart(2, '0')
  return `${y}/${m}/${d} ${hh}:${min}:${sin}`
})

Vue.config.productionTip = false
new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
